//
//  MicroAppModels.swift
//  TinyUI
//
//  Created by 徐涛 on 2020/3/27.
//  Copyright © 2020 葛晓良. All rights reserved.
//

import UIKit
import TinyUI
@objcMembers
class MicroAppModels: NSObject {
    
    var appName:String?
    var appKey:String?
    var size:String?
    var appVersion:String?
    var resourcesVersion:String?
    var mallGroup:String?
    var icon:String?
    var synopsis:String?
    var id:String?
    var appPlatform:String?
    var offStore:String?
    var isNeedNewMark:Bool=false
    var isInMy:Bool = false
    var sourceDic:NSMutableDictionary?
    var micAppType:String?
    var status:String?  //0上架 1下架
    var platform:String?  //0或者不存在为所有平台 1代表ios 2代表安卓
    var hasWidget:String?//1有  0没有
    var isHide:String?  //0显示 1隐藏
    
    override func setValue(_ value: Any?, forUndefinedKey key: String) {
        
    }
    
    
    func configWithParam(params:Dictionary<String,Any>)  {
        
        sourceDic = NSMutableDictionary.init(dictionary: params)
        
        if params["appName"] != nil {
            appName = "\(params["appName"]!)"
        }else if params["title"] != nil {
              appName = "\(params["title"]!)"
        }
        
        if params["appKey"] != nil {
            appKey = "\(params["appKey"]!)"
        }
        
        if params["appVersion"] != nil {
            appVersion = "\(params["appVersion"]!)"
        }
        
        if params["icon"] != nil {
            icon = "\(params["icon"]!)"
        }
        if params["status"] != nil {
            status = "\(params["status"]!)"
        }
        if params["platform"] != nil {
            platform = "\(params["platform"]!)"
        }
        let themeIcon:String = TinyTheme.config(withType: 1, param: String(format: "?theme/%@", appKey as! CVarArg))
        if themeIcon !=  String(format: "?theme/%@", appKey as! CVarArg){
            icon=themeIcon;
        }else{
            if params["thumbnailUrl"] != nil {
                
                if ((params["thumbnailUrl"] as? Dictionary<String,Any>) != nil) {
                    let themeName = TinyTheme.shareInstance().themeModel.themeName;
                    let dic:Dictionary<String,Any> = params["thumbnailUrl"] as! Dictionary<String,Any>
                    if dic[themeName] != nil {
                        icon = dic[themeName] as! String;
                    }else{
                        if dic["default"] != nil {
                            icon = dic["default"] as! String;
                        }
                    }
                }else{
                    icon = "\(params["thumbnailUrl"]!)"
                }
            }
        }
        if params["micAppType"] != nil {
            micAppType = "\(params["micAppType"]!)"
        }
        if params["isAdd"] != nil {
            let k:String=String.init(format: "%@", params["isAdd"] as! CVarArg)
            if (k == "1"){
                isInMy=true;
            }else{
                isInMy=false;
            }
        }
        if params["hasWidget"] != nil {
            hasWidget = "\(params["hasWidget"]!)"
        }
        
        if params["isHide"] != nil {
            isHide = "\(params["isHide"]!)"
        }
}


}
